home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / cvs-1_3.lha / cvs-1.3 / src / repos.c < prev    next >
C/C++ Source or Header  |  1992-03-31  |  4KB  |  170 lines

  1. /*
  2.  * Copyright (c) 1992, Brian Berliner and Jeff Polk
  3.  * Copyright (c) 1989-1992, Brian Berliner
  4.  * 
  5.  * You may distribute under the terms of the GNU General Public License as
  6.  * specified in the README file that comes with the CVS 1.3 kit.
  7.  * 
  8.  * Name of Repository
  9.  * 
  10.  * Determine the name of the RCS repository and sets "Repository" accordingly.
  11.  */
  12.  
  13. #include "cvs.h"
  14.  
  15. #ifndef lint
  16. static char rcsid[] = "@(#)repos.c 1.28 92/03/31";
  17. #endif
  18.  
  19. char *
  20. Name_Repository (dir, update_dir)
  21.     char *dir;
  22.     char *update_dir;
  23. {
  24.     FILE *fpin;
  25.     char *ret, *xupdate_dir;
  26.     char repos[PATH_MAX];
  27.     char path[PATH_MAX];
  28.     char tmp[PATH_MAX];
  29.     char cvsadm[PATH_MAX];
  30.     char ocvsadm[PATH_MAX];
  31.     char *cp;
  32.     int has_cvsadm = 0, has_ocvsadm = 0;
  33.  
  34.     if (update_dir && *update_dir)
  35.     xupdate_dir = update_dir;
  36.     else
  37.     xupdate_dir = ".";
  38.  
  39.     if (dir != NULL)
  40.     {
  41.     (void) sprintf (cvsadm, "%s/%s", dir, CVSADM);
  42.     (void) sprintf (ocvsadm, "%s/%s", dir, OCVSADM);
  43.     }
  44.     else
  45.     {
  46.     (void) strcpy (cvsadm, CVSADM);
  47.     (void) strcpy (ocvsadm, OCVSADM);
  48.     }
  49.  
  50.     /* sanity checks */
  51.     if (!(has_cvsadm = isdir (cvsadm)) && !(has_ocvsadm = isdir (ocvsadm)))
  52.     {
  53.     error (0, 0, "in directory %s:", xupdate_dir);
  54.     error (1, 0, "there is no version here; do '%s checkout' first",
  55.            program_name);
  56.     }
  57.  
  58.     if (has_ocvsadm)
  59.     {
  60.     if (has_cvsadm)
  61.     {
  62.         error (0, 0, "in directory %s:", xupdate_dir);
  63.         error (1, 0, "error: both `%s' and `%s' exist; I give up",
  64.            CVSADM, OCVSADM);
  65.     }
  66.     if (rename (ocvsadm, cvsadm) < 0)
  67.     {
  68.         error (0, 0, "in directory %s:", xupdate_dir);
  69.         error (1, errno, "cannot rename `%s' to `%s'; I give up",
  70.            OCVSADM, CVSADM);
  71.     }
  72.  
  73.     /*
  74.      * We have converted the old CVS.adm directory to the new CVS
  75.      * directory.  Now, convert the Entries file to the new format, if
  76.      * necessary.
  77.      */
  78.     check_entries (dir);
  79.     }
  80.  
  81.     if (dir != NULL)
  82.     (void) sprintf (tmp, "%s/%s", dir, CVSADM_ENT);
  83.     else
  84.     (void) strcpy (tmp, CVSADM_ENT);
  85.  
  86.     if (!isreadable (tmp))
  87.     {
  88.     error (0, 0, "in directory %s:", xupdate_dir);
  89.     error (1, 0, "*PANIC* administration files missing");
  90.     }
  91.  
  92.     if (dir != NULL)
  93.     (void) sprintf (tmp, "%s/%s", dir, CVSADM_REP);
  94.     else
  95.     (void) strcpy (tmp, CVSADM_REP);
  96.  
  97.     if (!isreadable (tmp))
  98.     {
  99.     error (0, 0, "in directory %s:", xupdate_dir);
  100.     error (1, 0, "*PANIC* administration files missing");
  101.     }
  102.  
  103.     /*
  104.      * The assumption here is that the repository is always contained in the
  105.      * first line of the "Repository" file.
  106.      */
  107.     fpin = open_file (tmp, "r");
  108.  
  109.     if (fgets (repos, PATH_MAX, fpin) == NULL)
  110.     {
  111.     error (0, 0, "in directory %s:", xupdate_dir);
  112.     error (1, errno, "cannot read %s", CVSADM_REP);
  113.     }
  114.     (void) fclose (fpin);
  115.     if ((cp = rindex (repos, '\n')) != NULL)
  116.     *cp = '\0';            /* strip the newline */
  117.  
  118.     /*
  119.      * If this is a relative repository pathname, turn it into an absolute
  120.      * one by tacking on the CVSROOT environment variable. If the CVSROOT
  121.      * environment variable is not set, die now.
  122.      */
  123.     if (strcmp (repos, "..") == 0 || strncmp (repos, "../", 3) == 0)
  124.     {
  125.     error (0, 0, "in directory %s:", xupdate_dir);
  126.     error (0, 0, "`..'-relative repositories are not supported.");
  127.     error (1, 0, "illegal source repository");
  128.     }
  129.     if (repos[0] != '/')
  130.     {
  131.     if (CVSroot == NULL)
  132.     {
  133.         error (0, 0, "in directory %s:", xupdate_dir);
  134.         error (0, 0, "must set the CVSROOT environment variable\n");
  135.         error (0, 0, "or specify the '-d' option to %s.", program_name);
  136.         error (1, 0, "illegal repository setting");
  137.     }
  138.     (void) strcpy (path, repos);
  139.     (void) sprintf (repos, "%s/%s", CVSroot, path);
  140.     }
  141.     if (!isdir (repos))
  142.     {
  143.     error (0, 0, "in directory %s:", xupdate_dir);
  144.     error (1, 0, "there is no repository %s", repos);
  145.     }
  146.  
  147.     /* allocate space to return and fill it in */
  148.     strip_path (repos);
  149.     ret = xstrdup (repos);
  150.     return (ret);
  151. }
  152.  
  153. /*
  154.  * Return a pointer to the repository name relative to CVSROOT from a
  155.  * possibly fully qualified repository
  156.  */
  157. char *
  158. Short_Repository (repository)
  159.     char *repository;
  160. {
  161.     if (repository == NULL)
  162.     return (NULL);
  163.  
  164.     /* if repository matches CVSroot at the beginning, strip off CVSroot */
  165.     if (strncmp (CVSroot, repository, strlen (CVSroot)) == 0)
  166.     return (repository + strlen (CVSroot) + 1);
  167.     else
  168.     return (repository);
  169. }
  170.